//
//  XJMainController.m
//  weiboOC
//
//  Created by 徐绩 on 16/4/17.
//  Copyright © 2016年 ayumi. All rights reserved.
//

#import "XJMainController.h"
#import "XJNavController.h"
#import "XJHomeController.h"
#import "XJDiscoveryController.h"
#import "XJMessageController.h"
#import "XJProfileController.h"
#import "XJTabBar.h"
#import "XJComposeView.h"

@interface XJMainController ()



@end

@implementation XJMainController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadChildViewControllers];
    
    XJTabBar *tabBar = [[XJTabBar alloc]initWithFrame:self.tabBar.bounds];
    
    tabBar.addBtnClickBlock = ^{    
//            Log(@"加号按钮点击");
        XJComposeView *composeView = [[XJComposeView alloc]initWithFrame:[UIScreen mainScreen].bounds];
//        [self.view addSubview:composeView];
        [composeView show:self];
        
    };
    
    [self setValue:tabBar forKey:@"tabBar"];
}

#pragma mark - 添加所有子控件
-(void)loadChildViewControllers{

    //首页
    XJHomeController *homeVC = [[XJHomeController alloc]init];

    
    //消息
    XJMessageController *messageVC = [[XJMessageController alloc]init];
    
    //发现
    XJDiscoveryController *disVC = [[XJDiscoveryController alloc]init];
    
    //我
    XJProfileController *proVC = [[XJProfileController alloc]init];

    [self loadVC:homeVC title:@"首页" imageName:@"tabbar_home"];
    [self loadVC:messageVC title:@"消息" imageName:@"tabbar_message_center"];
    [self loadVC:disVC title:@"发现" imageName:@"tabbar_discover"];
    [self loadVC:proVC title:@"我" imageName:@"tabbar_profile"];
}


-(void)loadVC:(UITableViewController *)VC title:(NSString *)title imageName:(NSString *)imageName{

    VC.title = title;
    
    VC.tabBarItem.image = [[UIImage imageNamed:imageName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    VC.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    [VC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor]} forState:UIControlStateSelected];
    
    XJNavController *nav = [[XJNavController alloc]initWithRootViewController:VC];

    [self addChildViewController:nav];
    
    
}



@end
